package com.jetlion.queue.queuearr;

import java.util.Scanner;

public class Main {
    //front队首的下表 rear队尾的下标 max数组的长度
    public static int front = -1, rear = -1, max = 3;

    //队列的数组
    public static int queue[] = new int[max];

    public static void main(String args[]){
        //控制流程的变量
        int M = 0;

        //控制台输入的数值
        int val=0;

        Scanner scanner=new Scanner(System.in);

        while (rear < max - 1 && M != 3) {
            System.out.print("[1]存入一个数值 [2]取出一个数值 [3]结束: ");
            M = scanner.nextInt();
            switch (M) {
                case 1:
                    System.out.print("\n[请输入数值]");
                    val = scanner.nextInt();
                    rear++;
                    queue[rear] = val;
                    break;
                case 2:
                    if (rear > front) {
                        front++;
                        System.out.print("\n[取出数值为]:[" + queue[front] + "]" + "\n");
                        queue[front] = 0;
                    } else {
                        System.out.print("\n [队列已经空了] \n");
                        break;
                    }
                    break;
                default:
                    System.out.print("\n");
                    break;
            }
        }
        if (rear == max - 1) {
            System.out.print("[队列已经满了] \n");
        }
        System.out.print("\n[目前队列中的数据]:");
        if (front >= rear) {
            System.out.print("没有\n");
            System.out.print(" [队列已经空了] \n");
        } else {
            while (rear > front) {
                front++;
                System.out.print("[" + queue[front] + "]");
            }
            System.out.print("\n");
        }
    }

}
